<template>
  <div class="dashboard-container">
    <el-drawer
      title="日期"
      :visible.sync="drawer"
      :direction="direction"
    >
      <div class="lunarFullCalendar">
        <div class="full-calendar">
          <lunar-full-calendar
            :events="events"
            ref="calendar"
            @event-selected="eventSelected"
            :config="config"
            @day-click="dayClick"
          ></lunar-full-calendar>
        </div>
      </div>
      <!-- <el-calendar :first-day-of-week=7 >
        <template slot="dateCell" slot-scope="{date, data}">
          <div style="width:100%;height:100%" @click="hanldeClick(data)">
            <p >
              {{ data.day.split('-').slice(2).join('-') }}<br />
            </p>
            <div class="red budge" v-for="(item,index) in dayOption" :key="index" v-if="(data.day).indexOf(item.day)!=-1"></div>
          </div>
          
        </template>
      </el-calendar> -->
      <div v-if="option.option">
        工作{{option.option}}
      </div>
    </el-drawer>
    <el-row class="flex">
      <!-- 左边 -->
      <el-col>
        <el-row class="flex">
          <el-card
            shadow="hover"
            v-for="o in 3"
            :key="o"
          >
            <div class="text item">
              {{'列表内容 ' + o }}
            </div>
          </el-card>
        </el-row>

        <el-row class="flex">
          <el-card
            shadow="hover"
            v-for="o in 4"
            :key="o"
          >
            <div class="text item">
              {{'列表内容 ' + o }}
            </div>
          </el-card>
        </el-row>

        <el-row class="flex">
          <el-card
            style="height: 370px;"
            shadow="hover"
            v-for="o in 2"
            :key="o"
          >
            <div class="text item">
              {{'列表内容 ' + o }}
            </div>
          </el-card>
        </el-row>

      </el-col>
      <!-- 右边 -->
      <el-col :span="8">
        <div class="grid-content bg-purple-dark">
          <el-row>
            <el-col :span="13">
              <el-card
                class="flex-one"
                shadow="hover"
              >
                <div
                  class="text item"
                  @click="checkTime"
                >
                  {{'列表内容 时间'}}
                </div>
              </el-card>
            </el-col>
            <el-col
              class="flex-one"
              :span="11"
            >
              <el-card shadow="hover">
                <div class="text item">
                  {{'列表内容 ' }}
                </div>
              </el-card>
            </el-col>
          </el-row>
          <el-card
            style="height: 320px;"
            shadow="hover"
          >
            <div class="text item">
              {{'列表内容 ' }}
            </div>
          </el-card>
          <el-card
            style="height: 190px;"
            shadow="hover"
          >
            <div class="text item">
              {{'列表内容 ' }}
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { LunarFullCalendar } from '../../lib/LunarFullCalendar.min.js'
export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters(['name'])
  },
  components: {
    LunarFullCalendar
  },
  data() {
    let self = this
    return {
      dayOption: [
        { day: '2021-05-30', option: '打工' },
        { day: '2021-05-10', option: '打工' },
        { day: '2021-05-01', option: '打工' },
        { day: '2021-05-02', option: '打工' },
        { day: '2021-05-03', option: '打工' },
        { day: '2021-05-04', option: '打工' }
      ],
      value: new Date(),
      option: {},
      drawer: false,
      direction: 'rtl',
      events: [
        {
          id: 1,
          title: '数据1',
          allDay: true,
          start: new Date()
        },
      ],
      config: {
        // lunarCalendar
        // Control whether the Chinese calendar shows true, unrealistic flase, default true.（lunarCalendar控制是否显示中国农历、显示的为true，隐藏为flase，默认为true）
        lunarCalendar: true,
        height: 'parent',
        locale: 'zh-cn',
        buttonText: {
          today: '今天',
          month: '月',
          week: '周',
          day: '日'
        },
        header: {
          left: 'prev,next, today',
          center: 'title',
          right: 'hide, custom, month,agendaWeek,agendaDay'
        },
        // eventOrder:'index',   // 这个是控制事件排序的功能，意思是 按照字段 事件数据中index来排序
        // eventLimitClick: 'day', //点击今天日列表图
        eventLimit: true, // 一天中显示多少条事件，多了隐藏
        firstDay: 0, // 控制周一周日那个在前面
        defaultView: 'month',
        allDaySlot: true, // agenda视图下是否显示all-day
        allDayText: '全天', // agenda视图下all-day的显示文本
        timezone: 'local', // 时区默认本地的
        slotLabelFormat: 'HH:mm', // 周视图和日视同的左侧时间显示
        viewRender(view, element) {
          self.viewRender(view, element)
        },
        customButtons: {
          // 新增按钮
          hide: {
            text: '隐藏农历',
            click: function() {
              self.$refs.calendar.fireMethod('option', {
                lunarCalendar: false
              })
              self.$refs.calendar.fireMethod('option', {
                header: {
                  left: 'prev,next, today',
                  center: 'title',
                  right: 'show, custom, month,agendaWeek,agendaDay'
                }
              })
            }
          },
          show: {
            text: '显示农历',
            click: function() {
              self.$refs.calendar.fireMethod('option', {
                lunarCalendar: true
              })
              self.$refs.calendar.fireMethod('option', {
                header: {
                  left: 'prev,next, today',
                  center: 'title',
                  right: 'hide, custom, month,agendaWeek,agendaDay'
                }
              })
            }
          }
        }
      }
    }
  },
  methods: {
    dayClick(date, jsEvent, view) {
      // 点击当天的事件
      console.log(date, jsEvent, 'dayClick')
    },
    eventSelected(event, jsEvent, view) {
      // 选中事件
      console.log(event, jsEvent, 'eventSelected')
    },
    viewRender(view, element) {
      console.log(view, element, 'viewRender')
    },
    enter() {
      this.$router.push('/explain')
    },
    hanldeClick(data) {
      
      this.option = {}
      this.dayOption.map(item => {
        if (item.day == data.day) {
          this.option = item
        }
      })
    },
    checkTime() {
      this.drawer = true
    }
  },
  mounted() {
    // console.log('el',this.$el)
  }
}
</script>

<style lang="scss" scoped>
.dashboard-container {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
  .el-card {
    flex: 1;
    height: 130px;
    margin: 10px;
  }
}
.current,
.next,
.prev {
  p {
    margin: 0;
    text-align: center;
  }
}

.budge {
  width: 10px;
  height: 10px;
  border-radius: 5px;
  margin: 5px auto;
}

.red {
  background-color: #c9413f;
}

.green {
  background-color: #25b591;
}

.orange {
  background-color: #ee915c;
}
</style>
